<template>
    <el-breadcrumb>
        <el-breadcrumb-item :to="{ path: 'home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>老师信息</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="serch">
        <el-input style="max-width: 600px" placeholder="输入搜索信息" v-model.trim="serchinfo">
            <template #prepend>
                教师工号
            </template>
            <template #append>
                <el-button @click="seach"><el-icon>
                        <Search />
                    </el-icon></el-button>
            </template>
        </el-input>
    </div>
    <div class="info" v-if="teacherdata.teacherid != null">
        <el-descriptions title="教师档案" border align="center">
            <el-descriptions-item :rowspan="2" :width="140" label="Photo" align="center">
                <el-image style="width: 100px; height: 100px"
                    src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
            </el-descriptions-item>
            <el-descriptions-item label="教师工号" align="center">{{ teacherdata.teacherid }}</el-descriptions-item>
            <el-descriptions-item label="姓名" align="center">{{ teacherdata.name }}</el-descriptions-item>
            <el-descriptions-item label="专业" align="center">{{ teacherdata.major_name }}</el-descriptions-item>
            <el-descriptions-item label="入职时间" align="center">{{ teacherdata.create_time }}</el-descriptions-item>
            <el-descriptions-item label="担任职位" align="center">{{ teacherdata.job_name }}</el-descriptions-item>
            <el-descriptions-item label="奖项" span="2" align="center">
                <p v-for="(item, i) in honorlist" :key="i">
                    {{ item.name }} {{ item.create_time }}
                </p>
            </el-descriptions-item>
            <el-descriptions-item label="操作" align="center" v-if="userstore.userinfo.roleid==1">
                <el-button>编辑</el-button>
            </el-descriptions-item>

        </el-descriptions>
    </div>
    <div v-else>
        <el-empty :image-size="200" />
    </div>
</template>

<script setup lang='ts'>
import { ref } from 'vue'
import { teacherinfo } from '@/apis/teacher'
import { ElMessage } from 'element-plus'
// @ts-ignore
import { Userstore } from '@/stores/user.js';
const userstore = Userstore()
const serchinfo = ref<string>('')
const teacherdata = ref<any>({})
const honorlist = ref<any>([])
const seach = async () => {
    if (serchinfo.value == '') return ElMessage({ type: 'warning', message: '请输入搜索的值' })
    const res = await teacherinfo({ teacherid: serchinfo.value })
    teacherdata.value = res.data.data.teacherinfo
    honorlist.value = res.data.data.honorlist
}
</script>
<style lang='scss' scoped>
.serch {
    margin-top: 15px;

    .el-button {
        color: #fff;
        background-color: #43a0ff;
    }
}
</style>